package com.michael.leetcode;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class SummaryRanges_228 {
    public List<String> summaryRanges(int[] nums) {
        int s = 0;
        int e = 0;
        List<String> res = new ArrayList<>();
        while (e < nums.length){
            if (e+1 >= nums.length){
                if (s == e){
                    res.add(nums[s]+"");
                }else {
                    res.add(nums[s]+"->"+nums[e]);
                }
                e++;
            }else if(nums[e+1]-nums[e] == 1){
                e++;
            }else {
                if (s == e){
                    res.add(nums[s]+"");
                }else {
                    res.add(nums[s]+"->"+nums[e]);
                }
                s = e+1;
                e = e+1;
            }
        }
        return res;
    }

    @Test
    public void test(){
        int[] nums = {0,1,2,4,5,7};
        List<String> strings = summaryRanges(nums);
    }
}